package com.example.service.impl;

import com.example.Repository.TagRepository;
import com.example.domain.property.Tag;
import com.example.domain.property.Type;
import com.example.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

@Service
public class TagServiceImpl implements TagService {
    @Autowired
    private TagRepository tagRepository;
    //新增
    @Override
    public boolean insert(Tag tag) {
        return false;
    }
    //查询一个
    @Override
    public Tag selectOne(Long id) {
        Optional<Tag> optional = tagRepository.findById(id);
        Tag tag=optional.get();
        //Type type = typeRepository.getById(id);
        return tag;
    }
    //分页查询多个
    @Override
    public Page<Tag> selectTypePage(int currentPage, int PageSize) {
        Pageable pageable = PageRequest.of(currentPage, PageSize);
        Page<Tag> page = tagRepository.findAll(pageable);
        return page;
    }
    //更新
    @Override
    public boolean updateById(Tag tag) {
        return false;
    }
    //id删除
    @Override
    public boolean deleteById(Long id) {
        return false;
    }
    //根据字符串里的多个id值查询(添加文章)
    @Override
    public List<Tag> selectListTag(List<Long> list) {
        return null;
    }
    //根据字符串中的id组获取数据
    @Override
    public List<Tag> listTag(String ids) {
        List<Long> list=new ArrayList<>();
        String[] split = ids.split(",");
        Arrays.stream(split).forEach(num->list.add(Long.valueOf(num)));   //tagIds字符串为集合
        List<Tag> tagList = tagRepository.findAllById(list);
        return tagList;
    }
    //标签类获取标签信息
    @Override
    public List<Tag> findAll() {
        List<Tag> list = tagRepository.findAll();
        return list;
    }


}
